package com.ticket.sass.admin.dto.output.film;

import com.ticket.sass.admin.model.LabModel;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author ywb
 * @date 2022-12-07 15:28
 */
@Data
@ApiModel("排期信息")
public class DateScheduleOutput {
    private LocalDate date;
    private List<FilmScheduleListOutput> list;
    private List<LabModel> films;
    private List<LabModel> halls;
    
    public DateScheduleOutput() {
    }
    
    public DateScheduleOutput(LocalDate date) {
        this.date = date;
    }
    
    public DateScheduleOutput(LocalDate date, List<FilmScheduleListOutput> list) {
        this.date = date;
        this.list = list;
    }
    
    public List<LabModel> getFilms() {
        Set<String> uniqueFilmIds = new HashSet<>();
        List<LabModel> films = new ArrayList<>();
        
        for (FilmScheduleListOutput output : list) {
            // 如果影片ID是唯一的，则将影片名称和ID保存到LabModel列表中
            if (uniqueFilmIds.add(output.getFilmName())) {
                films.add(new LabModel(output.getFilmId(), output.getFilmName()));
            }
        }
        return films;
    }
    
    public List<LabModel> getHalls() {
        Set<String> uniqueHallIds = new HashSet<>();
        List<LabModel> halls = new ArrayList<>();
        
        for (FilmScheduleListOutput output : list) {
            // 如果影片ID是唯一的，则将影片名称和ID保存到LabModel列表中
            if (uniqueHallIds.add(output.getHall())) {
                halls.add(new LabModel(output.getHallId(), output.getHall()));
            }
        }
        return halls;
    }
}
